from django.contrib import admin
from ximport.models import UploadFile
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect

class UploadFileAdmin(admin.ModelAdmin):
    list_display = ("status_id", "original_name", "import_file", "created_at", "updated_at")
    actions = ["candle_chart"]
    
    def candle_chart(self, request, queryset):
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        print selected
        ct = ContentType.objects.get_for_model(queryset.model)
        print ct
        return HttpResponseRedirect("/ximport/draw_candle_chart?ct=%s&ids=%s" % (ct.pk, ",".join(selected)))
    
    candle_chart.short_description = "Display candle chart"

admin.site.register(UploadFile, UploadFileAdmin)

